﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

public partial class GroupScheduler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DoctorScheduler_ResourceHeaderCreated(object sender, ResourceHeaderCreatedEventArgs e)
    {
        Panel ResourceImageWrapper = e.Container.FindControl("ResourceImageWrapper") as Panel;
        ResourceImageWrapper.CssClass = "Resource" + e.Container.Resource.Key.ToString();

        Image img = e.Container.FindControl("DoctorImage") as Image;
        img.ImageUrl = "App_Themes/Default/Images/carvalho.png";
            //"Img/" + e.Container.Resource.Text.Split(' ')[1].ToLower() + ".png";
    }

    protected void GroupingDirectionComboBox_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        UpdateScheduler();
    }

    private void UpdateScheduler()
    {
        DoctorScheduler.GroupingDirection =
            (GroupingDirection)Enum.Parse(typeof(GroupingDirection), GroupingDirectionComboBox.SelectedValue);

        DoctorScheduler.Rebind();
    }
    protected void DoctorScheduler_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
    {
        RadScheduler scheduler = (RadScheduler)sender;

        if (e.Container.Mode == SchedulerFormMode.Insert || e.Container.Mode == SchedulerFormMode.Edit ||
            e.Container.Mode == SchedulerFormMode.AdvancedInsert || e.Container.Mode == SchedulerFormMode.AdvancedEdit)
        {
            TextBox subjectBox = (TextBox)e.Container.FindControl("SubjectTextBox");
            subjectBox.Text = e.Appointment.Subject;

            RadDateInput startInput = (RadDateInput)e.Container.FindControl("StartInput");
            startInput.DateFormat = scheduler.AdvancedForm.DateFormat + " " + scheduler.AdvancedForm.TimeFormat;
            startInput.SelectedDate = DoctorScheduler.DisplayToUtc(e.Appointment.Start);

            RadDateInput endInput = (RadDateInput)e.Container.FindControl("EndInput");
            endInput.DateFormat = scheduler.AdvancedForm.DateFormat + " " + scheduler.AdvancedForm.TimeFormat;
            endInput.SelectedDate = DoctorScheduler.DisplayToUtc(e.Appointment.End);

            CheckBox repeatCheck = e.Container.FindControl("RepeatCheckBox") as CheckBox;
            if (repeatCheck != null)
            {
                repeatCheck.Checked = e.Appointment.RecurrenceState == RecurrenceState.Master;
            }
        }
    }

    protected void DoctorScheduler_FormCreating(object sender, SchedulerFormCreatingEventArgs e)
    {
        if (e.Mode == SchedulerFormMode.Insert || e.Mode == SchedulerFormMode.AdvancedInsert ||
            e.Mode == SchedulerFormMode.Edit || e.Mode == SchedulerFormMode.AdvancedEdit)
        {
            e.Appointment.Resources.Add(DoctorScheduler.Resources.GetResourceByType("AppointmentType"));
            e.Appointment.Resources.Add(DoctorScheduler.Resources.GetResourceByType("Room"));
            e.Appointment.Resources.Add(DoctorScheduler.Resources.GetResourceByType("Doctor"));
        }
    }
}